<template>
  <router-view/>
</template>

<script setup>
import useSettingsStore from '@/store/modules/settings'
import {handleThemeStyle} from '@/utils/theme'
import {checkLogin, autoLogin} from "@/api/login"
import Cookies from "js-cookie"
import {encrypt, decrypt} from "@/utils/jsencrypt"
import {getToken, setToken} from '@/utils/auth'
import useUserStore from '@/store/modules/user'

const userStore = useUserStore()

// 校验登录状态，是否自动登录
const checkLogins = () => {
  const username = Cookies.get("username");
  const password = Cookies.get("password");
  const rememberMe = Cookies.get("rememberMe");
  // 获取历史token
  let token = getToken();
  if (Boolean(rememberMe)) {
    const realPass = decrypt(password);
    // checkLogin({code: token}).then(res => {
    //   if (res.live === 0) {
    //     // token 失效，自动登录
    //     autoLogin(username, realPass, res.temp).then(res => {
    //       if (res.code === 200) {
    //         setToken(res.token);
    //         userStore.setStoreToken(res.token);
    //         userStore.getInfo();
    //       }
    //     });
    //   }
    // });
  }
}

checkLogins();

onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme)
  })
})

</script>
